package Message;

import java.util.ArrayList;
import java.util.HashMap;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.ElementMap;

import GameMap.mChatMessage;
import GameModel.mCard;
import GameModel.mCardCombo;
import GameModel.mGame;
import Player.mPlayer;
/**
 * 
 * @author Christopher Vogel
 *
 */
public class XMLcontent {
	@Element(required = false)
	String string = null;
	
	@Element(required = false) 
	int ReferredMsgID = 0;

	@Element(required = false)
	mPlayer player = null;
	
	@ElementList(required = false) 
	ArrayList<mPlayer> playerlist;
	
	@ElementList(required = false) 
	ArrayList<mGame> gamelist;

	@ElementList(required = false)
	ArrayList<mCard> cards = null;
	
	@ElementList(required = false)
	ArrayList<mCard> haggis = null;
	
	@ElementList(required=false)
	ArrayList<XMLhandcards> handcards = null;

	@Element(required = false)
	mCardCombo combo = null;

	@Element(required = false)
	mGame game = null;

	@Element(required = false)
	mChatMessage chat = null;

//	@Element(required = false)
//	mCardList list = null;

	public String getString() {
		return string;
	}

	public void setString(@Element(name="string", required = false)String string) {
		this.string = string;
	}
	
	public int getReferredMsgID() {
		return ReferredMsgID;
	}

	public void setReferredMsgID(@Element(name="referredMsgID", required = false)int referredMsgID) {
		ReferredMsgID = referredMsgID;
	}


	public mPlayer getPlayer() {
		return player;
	}

	
	public void setPlayer(@Element(name="player", required = false)mPlayer player) {
		this.player = player;
	}

	public ArrayList<mCard> getCards() {
		return cards;
	}

	public void setCards(@ElementList(name="cards", required = false)ArrayList<mCard> cards) {
		this.cards = cards;
	}
	
	
	

	public ArrayList<XMLhandcards> getHandcards() {
		return handcards;
	}

	public void setHandcards(@ElementList(name="handcards", required = false) ArrayList<XMLhandcards> handcards) {
		this.handcards = handcards;
	}

	public ArrayList<mPlayer> getPlayerlist() {
		return playerlist;
	}

	public void setPlayerlist(ArrayList<mPlayer> playerlist) {
		this.playerlist = playerlist;
	}

	public ArrayList<mCard> getHaggis() {
		return haggis;
	}

	public void setHaggis(ArrayList<mCard> haggis) {
		this.haggis = haggis;
	}

	public mCardCombo getCombo() {
		return combo;
	}

	public void setCombo(mCardCombo combo) {
		this.combo = combo;
	}

	public mGame getGame() {
		return game;
	}

	public void setGame(@Element(name="game",required = false)mGame game) {
		this.game = game;
	}

	public mChatMessage getChat() {
		return chat;
	}

	public void setChat(@Element(name="chat",required = false)mChatMessage chat) {
		this.chat = chat;
	}

//	public mCardList getList() {
//		return list;
//	}
//
//	public void setList(mCardList list) {
//		this.list = list;
//	}
	
	

	public ArrayList<mPlayer> getPlayerList() {
		return playerlist;
	}

	public void setPlayerList(@ElementList(name="playerlist", required = false)ArrayList<mPlayer> playerlist) {
		this.playerlist = playerlist;
	}
	
	

	public ArrayList<mGame> getGamelist() {
		return gamelist;
	}

	public void setGamelist(@ElementList(name="gamelist", required = false)ArrayList<mGame> gamelist) {
		this.gamelist = gamelist;
	}

	
	public ArrayList<mCard> getHandCarsByPlayerNumber(int Number) {
		return this.handcards.get(Number).getHandcardsOfPlayer();
	}
	
	public ArrayList<ArrayList<mCard>> getHandCardsList() {
		ArrayList<ArrayList<mCard>> hc = new ArrayList<ArrayList<mCard>>(3);
		for (XMLhandcards hcOfP: this.handcards) {
			hc.add(hcOfP.getHandcardsOfPlayer());
		}
		System.out.println("getHK-msg: "+hc);
		return hc;
	}
	
	public void setHandCardsList(ArrayList<ArrayList<mCard>> hc) {
		this.handcards.clear();
		for (ArrayList<mCard> hcOfP: hc) {
			this.handcards.add(new XMLhandcards(hcOfP));
		}		
	}
	
	public XMLcontent(
			@Element(name = "string", required = false) String string,
			@Element(name = "ReferredMsgID", required = false) int ReferredMsgID,
			@Element(name = "player", required = false) mPlayer player,
			@ElementList(name = "playerlist", required = false) ArrayList<mPlayer> playerlist,
			@ElementList(name = "gamelist", required = false) ArrayList<mGame> gamelist,
			@ElementList(name = "cards", required = false) ArrayList<mCard> cards,
			@ElementList(name = "handcards", required=false) ArrayList<XMLhandcards> handcards,
			@ElementList(name = "haggis", required = false) ArrayList<mCard> haggis,
			@Element(name = "combo", required = false) mCardCombo combo,
			@Element(name = "game", required = false) mGame game,
			@Element(name = "chat", required = false) mChatMessage chat/*,
			@Element(name = "list", required = false) mCardList list*/) {
		super();
		this.string = string;
		this.ReferredMsgID = ReferredMsgID;
		this.playerlist = playerlist;
		this.player = player;
		this.gamelist= gamelist;
		this.cards = cards;
		this.handcards=handcards;
		this.haggis=haggis;
		this.combo = combo;
		this.game = game;
		this.chat = chat;
		//this.list = list;
	}

	public XMLcontent() {
		super();
		this.handcards=new ArrayList<XMLhandcards>(3);
	}

	@Override
	public String toString() {
		return "XMLcontent ["
				+ (string != null ? "string=" + string + ", " : "")
				+ "ReferredMsgID=" + ReferredMsgID + ", "
				+ (player != null ? "player=" + player + ", " : "")
				+ (playerlist != null ? "playerlist=" + playerlist + ", " : "")
				+ (gamelist != null ? "gamelist=" + gamelist + ", " : "")
				+ (cards != null ? "cards=" + cards + ", " : "")
				+ (haggis != null ? "haggis=" + haggis + ", " : "")
				+ (handcards != null ? "handcards=" + handcards + ", " : "")
				+ (combo != null ? "combo=" + combo + ", " : "")
				+ (game != null ? "game=" + game + ", " : "")
				+ (chat != null ? "chat=" + chat : "") + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ReferredMsgID;
		result = prime * result + ((cards == null) ? 0 : cards.hashCode());
		result = prime * result + ((chat == null) ? 0 : chat.hashCode());
		result = prime * result + ((combo == null) ? 0 : combo.hashCode());
		result = prime * result + ((game == null) ? 0 : game.hashCode());
		result = prime * result
				+ ((gamelist == null) ? 0 : gamelist.hashCode());
		result = prime * result + ((haggis == null) ? 0 : haggis.hashCode());
		result = prime * result
				+ ((handcards == null) ? 0 : handcards.hashCode());
		result = prime * result + ((player == null) ? 0 : player.hashCode());
		result = prime * result
				+ ((playerlist == null) ? 0 : playerlist.hashCode());
		result = prime * result + ((string == null) ? 0 : string.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		XMLcontent other = (XMLcontent) obj;
		if (ReferredMsgID != other.ReferredMsgID)
			return false;
		if (cards == null) {
			if (other.cards != null)
				return false;
		} else if (!cards.equals(other.cards))
			return false;
		if (chat == null) {
			if (other.chat != null)
				return false;
		} else if (!chat.equals(other.chat))
			return false;
		if (combo == null) {
			if (other.combo != null)
				return false;
		} else if (!combo.equals(other.combo))
			return false;
		if (game == null) {
			if (other.game != null)
				return false;
		} else if (!game.equals(other.game))
			return false;
		if (gamelist == null) {
			if (other.gamelist != null)
				return false;
		} else if (!gamelist.equals(other.gamelist))
			return false;
		if (haggis == null) {
			if (other.haggis != null)
				return false;
		} else if (!haggis.equals(other.haggis))
			return false;
		if (handcards == null) {
			if (other.handcards != null)
				return false;
		} else if (!handcards.equals(other.handcards))
			return false;
		if (player == null) {
			if (other.player != null)
				return false;
		} else if (!player.equals(other.player))
			return false;
		if (playerlist == null) {
			if (other.playerlist != null)
				return false;
		} else if (!playerlist.equals(other.playerlist))
			return false;
		if (string == null) {
			if (other.string != null)
				return false;
		} else if (!string.equals(other.string))
			return false;
		return true;
	}

	

}
